package com.network.retrofit_rx.download;

import android.content.Context;

import java.io.File;

/**
 *
 * @author QiQi
 * @date 2017/8/23
 */

public class DownLoadUtil implements IFileLoadCallback {

    private IFileLoadCallback callback;

    private static class SingleHolder {
        static DownLoadUtil instance = new DownLoadUtil();
    }

    public static DownLoadUtil getInstance() {
        return SingleHolder.instance;
    }

    public void onAttach(IFileLoadCallback callback) {
        this.callback = callback;
    }

    public void onDetach() {
        this.callback = null;
    }


    @Override
    public void onSuccess(File file) {
        if (callback != null) {
            callback.onSuccess(file);
        }
    }

    @Override
    public void onFailure(Throwable t) {
        if (callback != null) {
            callback.onFailure(t);
        }
    }

    @Override
    public void onProgress(long progress, long total) {
        if (callback != null) {
            callback.onProgress(progress, total);
        }
    }

    /**
     * 启动下载服务
     *
     * @param context
     * @param url
     */
    public void startDownLoadService(Context context, String url, String ip) {
        DownLoadService.startService(context, url, ip);
    }
}
